﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using CdcSoftware.Pivotal.Applications.Core.Client;
using System.Data;
using CdcSoftware.Pivotal.Applications.Core.Common;
using CdcSoftware.Pivotal.Engine;
using CdcSoftware.Pivotal.Engine.Client.Services.Interfaces;
using Pcm.Retail.Client;
using System.Windows.Forms;
using CdcSoftware.Pivotal.Engine.UI.Forms;
using CdcSoftware.Pivotal.Engine.UI.DataTypes.Navigation;
using CdcSoftware.Pivotal.Engine.Client.Types;
using CdcSoftware.Iaf.SmartClient.Message;

namespace Pcm.Retail.Client.FormTasks
{
    public partial class RE_Promotion_SelectionList : FormClientTask
    {   
        /// <summary>
        /// Remove platform buttons and add custom button.
        /// </summary>
        private void AddRemoveButtons()
        {
            try
            {
                ButtonBarButton btnCancel = this.ButtonBar.Buttons["Cancel"];
                this.ButtonBar.Buttons.Clear();

                ButtonBarButton btnAuthorize = new ButtonBarButton();
                btnAuthorize.DisplayName = "Select Promotion(s)";
                btnAuthorize.ImageName = "Promotion";
                btnAuthorize.Name = "Promotion";
                this.ButtonBar.Buttons.Add(btnAuthorize);
                Command strcommand = Globals.SystemClient.UserProfile.GetMetaItem<Command>("RE_Promotion_SelectionList.OnClickSelectPromotion");
                IActionService actionService = ClientContext.ClientAPIService.GetService<IActionService>();
                if (strcommand.ClientTaskId != null)
                {
                    CdcSoftware.Pivotal.Engine.Client.Types.CommandHandler strcommandHandler = Globals.SystemClient.UserProfile.GetMetaItem<CdcSoftware.Pivotal.Engine.Client.Types.CommandHandler>(strcommand.CommandHandlerId);
                    IClientTaskActionTarget clientTaskActionTarget1 = actionService.CreateActionTarget<IClientTaskActionTarget>();
                    clientTaskActionTarget1.ClientTask = strcommand.ClientTaskId;
                    clientTaskActionTarget1.ClientTaskMethod = strcommandHandler.MethodName;
                    IAction action1 = actionService.CreateAction(string.Empty, ActionCommand.Show, ActionContent.ClientTask, clientTaskActionTarget1);
                    btnAuthorize.Action = (CommandMessage)action1;
                }

                this.ButtonBar.Buttons.Add(btnCancel);
            }
            catch (Exception ex)
            {
                Globals.HandleException(ex, true);
            }
        }
    }
}
